import { useRequest } from 'umi';
import {
  queryCardList,
  queryCardType,
  queryCardInfo,
  addCardAPI,
  deleteCardAPI,
  queryUnboundUserList,
  activateCardAPI,
  stopCardAPI,
  restoreCardAPI,
} from '@/pages/Card/services';
import { createModel } from 'hox';

export interface TableListItem {
  createTime: string;
  cardType: number;
  id: number;
  status: number;
  cardNo: string;
}
function useCardModel() {
  //获取卡片接口
  const { run: getCardList } = useRequest(queryCardList, {
    manual: true,
  });
  //获取卡片类型接口
  const { run: getCardType, data: cardTypeList } = useRequest(queryCardType, { manual: true });
  //新增卡片接口
  const { run: addCard } = useRequest(addCardAPI, {
    manual: true,
    formatResult: (res) => res,
  });
  //获取卡片详情接口
  const {
    run: getCardInfo,
    data: cardInfo,
    loading: getCardInfoLoading,
  } = useRequest(queryCardInfo, { manual: true });

  //获取卡片类型接口
  const { run: deleteCard } = useRequest(deleteCardAPI, {
    manual: true,
    formatResult: (res) => res,
  });
  const { run: lossCard } = useRequest(stopCardAPI, {
    manual: true,
    formatResult: (res) => res,
  });

  //激活卡片
  const { run: activateCard } = useRequest(activateCardAPI, {
    manual: true,
    formatResult: (res) => res,
  });

  //恢复卡片
  const { run: restoreCard } = useRequest(restoreCardAPI, { manual: true });
  //获取用户列表接口
  const { run: getUnboundUserList, data: userList } = useRequest(queryUnboundUserList, {
    manual: true,
  });
  return {
    getCardList,
    getCardInfo,
    getCardType,
    cardTypeList,
    getCardInfoLoading,
    activateCard,
    cardInfo,
    userList,
    addCard,
    restoreCard,
    lossCard,
    getUnboundUserList,
    deleteCard,
  };
}
export default createModel(useCardModel);
